"""
@Author  : 康帅
@Time    : 2021/3/15 9:41
@Function: 单例模式案列
"""


class MyBeautifulGirl(object):
    """  我的漂亮女神 """

    __instance = None
    __isFirstInit = False

    def __new__(cls, name):
        """ __new__负责对象的创建,__new__是一个类方法 """

        if not cls.__instance:
            MyBeautifulGirl.__instance = super().__new__(cls)
        return cls.__instance

    def __init__(self, name):
        """ __init__负责对象的初始化,__init__是一个对象方法 """

        if not self.__isFirstInit:
            self.__name = name
            print("遇见" + name + ",一见钟情")
            MyBeautifulGirl.__isFirstInit = True
        else:
            print("遇见" + name + ",我置若盲闻")

    def show_my_heart(self):
        print(self.__name + "是我心中的唯一")


if __name__ == '__main__':
    jenny = MyBeautifulGirl("Jenny")
    jenny.show_my_heart()
    kimi = MyBeautifulGirl("Kimi")
    kimi.show_my_heart()
    print("id(jenny):", id(jenny), "id(kimi):", id(kimi))
